<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>object.html</title>
<script>
//리터럴 타입으로 객체 생성

var obj={};
obj.irum='Lee';
obj.kor=90;
obj.eng=90;
obj.sum= obj.kor+obj.eng;

// 출력
 document.write("<li>name : "+obj.irum);
 document.write("<li>kor:"+obj.kor);
 document.write("<li>eng:"+obj.eng);
 document.write("<li>sum:"+obj.sum);
 
 //리터널 타입으로 setter/getter생성하기
  var score={};
 score.setIrum=function(irum){this.irum=irum;};
 score.setKor=function(k){this.kor=k;};
 score.setEng=function(e){this.eng=e;};
 score.compute=function(){ this.sum=this.kor+this.eng;};
 
 
 score.getIrum=function(){ return this.irum;};
 score.getKor=function(){ return this.kor;};
 score.getEng=function(){ return this.eng;};
 score.getSum=function(){ return this.sum;};
 
 
 //값 저장
  score.setIrum("Kim");
  score.setKor(50);
  score.setEng(30);
  score.compute();
  
  //출력
  
  document.write("<hr/>");
  document.write("<li>Irum:"+score.getIrum());
  document.write("<li>Kor:"+score.getKor());
  document.write("<li>Eng:"+score.getEng());
  document.write("<li>Sum:"+score.getSum());
  
  
  //자바 클래스선언유형과 유사하게 자바스크립트 객체 생성
   function Score(irum, kor, eng){
	   this.irum=irum;
	   this.kor=kor;
	   this.eng=eng;
	   
	   this.setIrum=function(irum){this.irum=irum;};
	   this.setKor=function(k){this.kor=k;};
	   this.setEng=function(e){this.eng=e;};
	   this.compute=function(){ this.sum=this.kor+this.eng;};
	   
	   this.getIrum=function(){ return this.irum;};
	   this.getKor=function(){ return this.kor;};
	   this.getEng=function(){ return this.eng;};
	   this.getSum=function(){ return this.sum;};
	   
	  this.toString=function(){
		  document.write(this.irum+"&nbsp;&nbsp;&nbsp;&nbsp;");
		  document.write(this.kor+"&nbsp;&nbsp;&nbsp;&nbsp;");
		  document.write(this.eng+"&nbsp;&nbsp;&nbsp;&nbsp;");
		  document.write(this.sum+"<br/>");

	  }
  }
 
document.write("<hr/>");
//Score 객체를 s로 생성
 s= new Score('lee',100,100);
 s.compute();
 s.toString();
 
 s2 = new Score('choi',60,70);
 s2.compute();
 s2.toString();
 
</script>

</head>
<body>

</body>
</html>